﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DAO;
using DAO_DTO_WS.DTO;

namespace LayoutTemplate
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            string tendangnhap = tbTenDangNhap.Text.Trim();
            if ((ThanhVienDAO.KiemTra(tendangnhap)) || (DoanhNghiepDAO.KiemTra(tendangnhap)))
            {
                Response.Redirect("TrangLoi.aspx?Error=5");
            }
            else
            {
                ThanhVienDTO thanhvien = new ThanhVienDTO();
                DoanhNghiepDTO doanhnghiep = new DoanhNghiepDTO();
                thanhvien.TenThanhVien = tbTenDangNhap.Text.Trim();
                thanhvien.MatKhau = tbMatKhau.Text;
                thanhvien.Email = tbEmail.Text;
                thanhvien.HoTen = tbTenDN.Text;
                thanhvien.NgaySinh = new DateTime(1990, 1, 1);
                thanhvien.GioiTinh = 1;
                thanhvien.TinhTrang = 2;
                thanhvien.TaiKhoan = 0;
                thanhvien.NguyenQuan = "";
                thanhvien.NoiO = "";
                thanhvien.DienThoai = tbDienThoai.Text;
                thanhvien.Avatar = "";
                ThanhVienDAO.ThemMoi(thanhvien);
                doanhnghiep.TenDangNhap = tbTenDangNhap.Text;
                doanhnghiep.MatKhau = tbMatKhau.Text;
                doanhnghiep.TenDoanhNghiep = tbTenDN.Text;
                doanhnghiep.TinhTrang = 1;
                doanhnghiep.DiaChi = tbDiaChi.Text;
                doanhnghiep.DienThoai = tbDienThoai.Text;
                doanhnghiep.WebSite = tbWeb.Text;
                DoanhNghiepDAO.ThemMoi(doanhnghiep);
                Response.Redirect("TrangLoi.aspx?Error=4");
            }
        }
        
    }
}
